package org.particlethink.response;

import io.swagger.v3.oas.annotations.media.Schema;
import org.particlethink.entry.OrderStatus;
import org.particlethink.model.*;

import java.util.Date;

public class OrderResponse {
    private int id;
    @Schema(description = "订单编号")
    private String no;
    @Schema(description = "批次计划id")
    private int batchPlanId;//批次计划
    @Schema(description = "批次计划编号")
    private String batchPlanNo;
    @Schema(description = "总计划id")
    private int masterPlanId;//批次计划
    @Schema(description = "总计划编号")
    private String masterPlanNo;

    @Schema(description = "供货商")
    private SupplierResponse supplier;//供货商
    @Schema(description = "物料大类")
    private CategoryResponse category;//物料大类
    @Schema(description = "项目")
    private ProjectResponse project;

    @Schema(description = "状态 1：待发货；2：异常退回；3：进行中；4：已完成")
    private OrderStatus status;
    @Schema(description = "备注(拒绝原因)")
    private String remark;//备注
    @Schema(description = "下单时间")
    private Date createdAt;
    @Schema(description = "创建者")
    private ProjectUserResponse creator;//创建者
    @Schema(description = "重新发起过")
    private boolean hasReCreated;

    @Schema(description = "最晚进场时间")
    private Date deadlineAt;//最晚进场时间

    @Schema(description = "全部发货")
    private boolean hasAllShipment;

    @Schema(description = "买方取消")
    private boolean hasCancel;

    @Schema(description = "买方取消")
    private boolean hasComplete;

    public OrderResponse() {
    }

    public OrderResponse(
            Order order,
            Supplier supplier,
            Category category,
            Project project,
            ProjectUser creator
    ) {
        this.id = order.getId();
        this.no = order.getNo();
        this.batchPlanId = order.getBatchPlanId();
        this.batchPlanNo = order.getBatchPlanNo();
        this.supplier = supplier == null ? null : new SupplierResponse(supplier);
        this.category = category == null ? null : new CategoryResponse(category);
        this.project = project == null ? null : new ProjectResponse(project);
        this.status = order.getStatus();
        this.remark = order.getRemark();
        this.creator = creator == null ? null : new ProjectUserResponse(creator);
        this.createdAt = order.getCreatedAt();
        this.batchPlanId = order.getBatchPlanId();
        this.hasReCreated = order.getHasReCreated();
        this.masterPlanId = order.getMasterPlanId();
        this.masterPlanNo = order.getMasterPlanNo();
        this.deadlineAt = order.getDeadlineAt();
        this.hasCancel = order.getStopped() && order.getStatus() != OrderStatus.Done;
        this.hasComplete = order.getCompleted() && order.getStatus() != OrderStatus.Done;
        this.hasAllShipment = (!order.getStopped() && !order.getCompleted()) && order.getAllShipment();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public int getBatchPlanId() {
        return batchPlanId;
    }

    public void setBatchPlanId(int batchPlanId) {
        this.batchPlanId = batchPlanId;
    }

    public SupplierResponse getSupplier() {
        return supplier;
    }

    public void setSupplier(SupplierResponse supplier) {
        this.supplier = supplier;
    }

    public CategoryResponse getCategory() {
        return category;
    }

    public void setCategory(CategoryResponse category) {
        this.category = category;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }


    public ProjectResponse getProject() {
        return project;
    }

    public void setProject(ProjectResponse project) {
        this.project = project;
    }

    public ProjectUserResponse getCreator() {
        return creator;
    }

    public void setCreator(ProjectUserResponse creator) {
        this.creator = creator;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getBatchPlanNo() {
        return batchPlanNo;
    }

    public void setBatchPlanNo(String batchPlanNo) {
        this.batchPlanNo = batchPlanNo;
    }

    public boolean getHasReCreated() {
        return hasReCreated;
    }

    public void setHasReCreated(boolean hasReCreated) {
        this.hasReCreated = hasReCreated;
    }

    public int getMasterPlanId() {
        return masterPlanId;
    }

    public void setMasterPlanId(int masterPlanId) {
        this.masterPlanId = masterPlanId;
    }

    public String getMasterPlanNo() {
        return masterPlanNo;
    }

    public void setMasterPlanNo(String masterPlanNo) {
        this.masterPlanNo = masterPlanNo;
    }

    public Date getDeadlineAt() {
        return deadlineAt;
    }

    public void setDeadlineAt(Date deadlineAt) {
        this.deadlineAt = deadlineAt;
    }

    public boolean setHasCancel() {
        return hasCancel;
    }

    public void setHasCancel(boolean hasCancel) {
        this.hasCancel = hasCancel;
    }

    public boolean isHasAllShipment() {
        return hasAllShipment;
    }

    public void setHasAllShipment(boolean hasAllShipment) {
        this.hasAllShipment = hasAllShipment;
    }

    public boolean getHasCancel() {
        return hasCancel;
    }

    public boolean getHasComplete() {
        return hasComplete;
    }

    public void setHasComplete(boolean hasComplete) {
        this.hasComplete = hasComplete;
    }
}
